﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace database_select
{
    class Select_data
    {
        MySql.Data.MySqlClient.MySqlConnection conn;
        MySql.Data.MySqlClient.MySqlCommand cmd;
        public Select_data(MySql.Data.MySqlClient.MySqlConnection conn, MySql.Data.MySqlClient.MySqlCommand cmd)
        {
            this.conn = new MySql.Data.MySqlClient.MySqlConnection();
            this.conn = conn;
            this.cmd = cmd;
        }
        public string select_users(string s,int user_id)//берём нужное по user_id
        {
            //conn.Open;
        cmd.CommandText = "SELECT " +s+" FROM users WHERE user_id =" + user_id;
        MySql.Data.MySqlClient.MySqlDataReader myreader = cmd.ExecuteReader();
        myreader.Read();
        return myreader.GetString(0);
        }
       /*public user_instrument_forselect select_user_instruments(int user_id)//берём нужное по user_id
        {
            cmd.CommandText = "SELECT id_instrument FROM user_instruments WHERE user_id =" + user_id;
            MySql.Data.MySqlClient.MySqlDataReader myreader = cmd.ExecuteReader();
            myreader.Read();
            user_instrument_forselect oneid=new user_instrument_forselect();
            oneid.val_users=0;
             while(myreader.Read())
            {
                 oneid.id_instrument[oneid.val_users]=int.Parse(myreader.GetString(oneid.val_users));
                 oneid.val_users++;
            }
            return oneid;
        }*/
        //тут баг
        public string select_instruments(string inf, int id_instrument)//берём нужное inf по id_instrument
        {
            cmd.CommandText = "SELECT " + inf + " FROM instruments WHERE id_instrument =" + id_instrument;
            MySql.Data.MySqlClient.MySqlDataReader myreader = cmd.ExecuteReader();
            myreader.Read();
            return myreader.GetString(0);
        }
        public string select_events(string inf, int id_instrument)//берём нужное id_instrument
        {
            cmd.CommandText = "SELECT " + inf + " FROM events WHERE instruments_id_instrument =" + id_instrument;
            MySql.Data.MySqlClient.MySqlDataReader myreader = cmd.ExecuteReader();
            myreader.Read();
            return myreader.GetString(0);
        }
        struct user_instrument_forselect
        {
           public int val_users;
           public int[] id_instrument;
        }
    }
}
